package components.pacman;

import images.Images;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.events.constants.Key;

import components.PacmanComponent;
import components.Walker;
import components.direction.Direction;
import components.ghost.Ghost;

public class Pacman extends Walker {

	public Pacman() {
		super(20, 20, 0, 0);
		this.setAppearance(Images.getImage("pacman"));
		this.setSpeed(100);
		//this.setAppearance(new Circle(Color.YELLOW, 6));
	}

	public void effectiveUpdate(DeltaState delta){
		super.effectiveUpdate(delta);
		
		this.updateDirection(delta);
	}

	private void updateDirection(DeltaState delta) {
		if (delta.isKeyPressed(Key.DOWN)){
			this.setQueuedDir(Direction.SOUTH);
		}else if(delta.isKeyPressed(Key.UP)){
			this.setQueuedDir(Direction.NORTH);
		}else if(delta.isKeyPressed(Key.RIGHT)){
			this.setQueuedDir(Direction.EAST);
		}else if(delta.isKeyPressed(Key.LEFT)){
			this.setQueuedDir(Direction.WEST);
		}
	}
	
	@Override
	protected void defineCollide(PacmanComponent gc) {
		gc.onCollisionWithPacman(this);
	}
	
	public void onCollisionWithGhost(Ghost ghost){
		ghost.onCollisionWithPacman(this);
	}

	@Override
	public String appRootName() {
		return "pacman";
	}

	public void die() {
		this.getScene().pacmanDied(this);
	}
}
